package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/5 18:07
 */
public class J65 {

    // https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/
    public static int add(int a, int b) {
        return a+b;
    }

    public static int add2(int a, int b) {
        while(b != 0) { // 当进位为 0 时跳出
            int c = (a & b) << 1;  // c = 进位
            a ^= b; // a = 非进位和
            b = c; // b = 进位
        }
        return a;
    }

    // for test
    public static void main(String[] args) {
        int a = 1;
        int b = 1;
        System.out.println(add(a, b));
        System.out.println(add2(a, b));
    }

}
